﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;

namespace WebServer.BusinessLogic.Wrappers
{
    public class HttpWebRequestWrapper : IHttpWebRequestWrapper
    {
        private HttpWebRequest httpWebRequest;

        public void Create(Uri uri)
        {
            this.httpWebRequest = (HttpWebRequest) HttpWebRequest.Create(uri);
        }

        public Stream GetRequestStream()
        {
            return this.httpWebRequest.GetRequestStream();
        }

        public IHttpWebResponseWrapper GetResponse()
        {
            return new HttpWebResponseWrapper(this.httpWebRequest.GetResponse());
        }

        public Int64 ContentLength
        {
            get { return this.httpWebRequest.ContentLength; }
            set { this.httpWebRequest.ContentLength = value; }
        }
    }

    public interface IHttpWebRequestWrapper
    {
        void Create(Uri uri);
        Stream GetRequestStream();
        IHttpWebResponseWrapper GetResponse();
        Int64 ContentLength { get; set; }
    }

    public class HttpWebResponseWrapper : IHttpWebResponseWrapper
    {
        private HttpWebResponse httpWebResponse;

        public HttpWebResponseWrapper(WebResponse webResponse)
        {
            this.httpWebResponse = (HttpWebResponse) webResponse;
        }

        public long ContentLength
        {
            get { return this.httpWebResponse.ContentLength; }
        }

        public Stream GetResponseStream()
        {
            return httpWebResponse.GetResponseStream();
        }

        public string ContentType
        {
            get { return httpWebResponse.ContentType; }
        }

        public Version ProtocolVersion
        {
            get { return httpWebResponse.ProtocolVersion; }
        }

        public HttpStatusCode StatusCode
        {
            get { return httpWebResponse.StatusCode; }
        }

        public string StatusDescription
        {
            get { return httpWebResponse.StatusDescription; }
        }
    }

    public interface IHttpWebResponseWrapper
    {
        Int64 ContentLength { get; }
        Stream GetResponseStream();
        string ContentType { get; }
        Version ProtocolVersion { get; }
        HttpStatusCode StatusCode { get; }
        string StatusDescription { get; }
    }

    
}
